$(function(){

	var commentContent = $('#comment_content')


	var commentBtn = $('#comment_btn')

	var commentErr = $('#comment_err')

	var commentForm = $('#comment_form')

	var commentNum = $('#comment_num')

	var commentBuildingNum = $('#comment_buildingNum')

	var thumbsUp = $('.thumbs')

	var USER = $('#USER').val()


	commentBtn.on('click',function(){


		if(!USER){

			alert('请先登录再做评论')


			return
		}

		if(commentContent.val() == '' || commentContent.val().length == 0){


			commentErr.text('评论内容不能为空').show()


			return

		}

		commentBuildingNum.val(parseInt(commentBuildingNum.val())+1)


		commentForm.submit()


	})


	commentContent.on('keyup keydown',function(){

		if(commentErr.show()){

			commentErr.hide()
		}
	})

	thumbsUp.on('click',function(){

		if(!$(this).hasClass("active")){

		var _thumb = $(this)

		var thumbs = $(this).find('.thumbs-up-count')

		var thumbsCount = parseInt($(this).find('.thumbs-up-count').text())

		var commentId = $(this).next('.comment-id').val()

		$.ajax({
			type:'post',
			url:'/updateComment',
			data:{

				thumbsCount:thumbsCount+1,
				commentId : commentId

			},

			success:function(data){

				thumbs.text(data.thumbsCount)

				_thumb.addClass("active")
			}

		})

		}else{

			var _thumb = $(this)

			var thumbs = $(this).find('.thumbs-up-count')

			var thumbsCount = parseInt($(this).find('.thumbs-up-count').text())

			var commentId = $(this).next('.comment-id').val()

			$.ajax({
			type:'post',
			url:'/updateComment',
			data:{

				thumbsCount:thumbsCount-1,
				commentId : commentId

			},

			success:function(data){

				thumbs.text(data.thumbsCount)

				_thumb.removeClass("active")
			}

		})


		}
	})













})